Promise.myAllSettled = function (promises) {
	// count：用于统计个数，res存放每个promise的结果
	let count = 0,
		res = [];
	return new Promise((resolve, reject) => {
		promises.forEach((item, index) => {
			Promise.resolve(item)
				.then((val) => {
					count++;
					// 当状态为fulfilled时
					res[index] = { val: val, status: "fulfilled" };
					if (count === promises.length) {
						resolve(res);
					}
				})
                .catch((err) => {
                    // 当状态为rejected时
					count++;
					res[index] = { val: err, status: "rejected" };
				});
		});
	});
};

// test
let p1 = new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve(111);
	}, 1000);
});

let p2 = new Promise((resolve, reject) => {
	setTimeout(() => {
		reject(222);
	}, 2000);
});

let p3 = new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve(333);
	}, 3000);
});
Promise.myAllSettled([p1, p2, p3])
	.then((res) => {
		console.log(res);
	})
	.catch((err) => {
		console.log(err);
	});
